package main

import (
	"database/sql"
	"embed"
	"fmt"
	"goblog/app/http/middlewares"
	"goblog/bootstrap"
	"goblog/config"
	"goblog/pkg/logger"
	"net/http"

	"github.com/gorilla/mux"
)

//go:embed resources/views/articles/*
//go:embed resources/views/auth/*
//go:embed resources/views/categories/*
//go:embed resources/views/layouts/*
var tplFS embed.FS

//go:embed public/*
var staticFS embed.FS

var router *mux.Router
var db *sql.DB

// 未找到
func notFoundHandler(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(http.StatusNotFound)
	fmt.Fprint(w, "<h1>请求页面未找到 :(</h1><p>如有疑惑，请联系我们。</p>")
}

func inti() {
	 // 初始化配置信息
	config.Initialize()

}

func main() {
	// 初始化 SQL
	bootstrap.SetupDB()

	// 初始化模板
	bootstrap.SetupTemplate(tplFS)

	// 初始化路由绑定
    router := bootstrap.SetupRoute(staticFS)

	err := http.ListenAndServe(":3000", middlewares.RemoveTrailingSlash(router))
	logger.LogError(err)
}
